<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>阶乘</title>
		
	</head>
	<body>
		<tr>
			<td>
				<input type="text" id="num"/>
				<input type="button" id="btn" value="阶乘"/>
				<span id="result"></span>
			</td>
		</tr>
		<script type="text/javascript">
			document.getElementById("btn").onclick = function(){
				var num = document.getElementById('num').value;
				var result = 1;
				if(num < 0){
					result = "负数没有阶乘";
				}else if( num == 0){
					result = 1
				}else{
					for (var i =num ;i>0;i--) {
					result *= i;
					}
				}						
				document.getElementById("result").innerHTML = "=" + result;
			};
			
		</script>
	</body>
</html>
